(* 实现了一个二叉搜索树（Binary Search Tree, BST）的插入函数 *)

type 'a binary_tree =
  | Empty
  | Node of 'a * 'a binary_tree * 'a binary_tree   (* 当前节点 ，当前左子树，当前右子树 *)
;;

let rec insert tree x = match tree with
    | Empty -> Node(x, Empty, Empty)
    | Node(y, l, r) ->
       if x = y then tree
       else if x < y then Node(y, insert l x, r)
       else Node(y, l, insert r x)

let construct l = List.fold_left insert Empty l
;;
      
construct [3; 2; 5; 7; 1];;